package TestClass;

import Day01_Reflect.ReflectTest;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Properties;

public class ReflectDemo {
    public static void main(String[] args) throws Exception {
        //1.创建Properties对象
        Properties prop = new Properties();
        //1.1加载config文件
        ClassLoader classLoader = ReflectDemo.class.getClassLoader();
        InputStream is = classLoader.getResourceAsStream("config.properties");
        prop.load(is);
/*        URL url1 = classLoader.getResource("config.properties");
        URL url2 = classLoader.getResource("Demo101_Reflect");
        System.out.println(url1);
        System.out.println(url2);*/
 /*       ClassLoader cls2 = ReflectTest.class.getClassLoader();
        URL url = cls2.getResource("config.properties");
        System.out.println(url);*/
        //2.获取配置文件中配置的数据
        String className = prop.getProperty("className");
        String methodName = prop.getProperty("methodName");
        //3.加载该类进内存
        Class cls = Class.forName(className);
        //4.创建对象
        Object obj = cls.newInstance();
        //5.获取方法对象
        Method method = cls.getMethod(methodName);
        //6.执行方法
        method.invoke(obj);
    }
}
